<!--
 * @Author: Zhong
 * @Description: $1
 * @FilePath: \tenement-admin\src\views\operateManage\complain\addEdit.vue
 * @LastEditTime: 2024-10-21 23:53:18
 * @LastEditors: Zhong
-->

<template>
  <el-dialog
    title="处理投诉"
    v-model="model"
    width="600px"
    :before-close="handleClose"
  >
    <el-form ref="auditFormRef" :model="auditForm" label-width="80px">
      <el-form-item label="状态" prop="status">
        <el-select v-model="auditForm.status" placeholder="请选择状态">
          <el-option label="待处理" :value="0" />
          <el-option label="已处理" :value="1" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <div>
        <el-button @click="model = false">取 消</el-button>
        <el-button type="primary" @click="submitAudit">确 定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref } from "vue";
import { getCurrentInstance } from "vue";
import { updateComplain } from "@/api/system/complain";

const { proxy } = getCurrentInstance();

const props = defineProps({
  row: {
    type: Object,
    required: true,
  },
});
const model = defineModel({
  default: false,
});
const emit = defineEmits(["submit"]);
const isEdit = computed(() => !!props.row.id);

onMounted(() => {
  if (isEdit.value) {
    auditForm.value.status = props.row.status;
  }
});
const auditFormRef = ref(null);
const auditForm = ref({
  status: 0,
});

const submitAudit = () => {
  auditFormRef.value.validate((valid) => {
    if (valid) {
      updateComplain({
        ...auditForm.value,
        id: props.row.id,
      }).then(({ data }) => {
        if (data) {
          proxy.$modal.msgSuccess("修改成功");
          model.value = false;
          emit("submit");
        }
      });
    }
  });
};

// ... existing onMounted and other logic ...
</script>
